package com.crimsec.utils.snmp.model;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

/**
 * $Id$ представляет собой данные snmp со ссылкой на событие запроса, и
 * переменную mib
 *
 */
@Entity
@Table(name = "eventdata")
@XmlRootElement
@XmlType(name = "data")
@NamedQueries({
    @NamedQuery(
        name = "Eventdata.findAll",
    query = "SELECT e FROM Eventdata e"),
    @NamedQuery(
        name = "Eventdata.findById",
    query = "SELECT e FROM Eventdata e WHERE e.id = :id"),
    @NamedQuery(
        name = "Eventdata.findByEvent",
    query = "SELECT e FROM Eventdata e WHERE e.event = :event")
})
@SequenceGenerator(name = "seq_evdata", sequenceName = "seq_evdata", allocationSize = 1)
public class Eventdata extends AbstractEntity implements Serializable {

    private static final long serialVersionUID = 1L;
    //
    @Id
    @Basic(optional = false)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_evdata")
    @Column(name = "id")
    private Long id;
    /*значение переменной mib (фактически 'variant') 
     преобразовывать основываясь на enttype*/
    @Column(name = "entval")
    private String entval;
    //ссылка на переменную mib
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "ent_id", referencedColumnName = "id")
    private Mibent mibent;
    //ссылка на событие 
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "event_id", referencedColumnName = "id")
    private Event event;

    public Eventdata() {
    }

    public Eventdata(Event event, Mibent mibent, String value) {
        this.event = event;
        this.mibent = mibent;
        this.entval = value;
    }

    @XmlAttribute
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    /**
     *
     * @return значение переменной mib из snmp-запроса
     */
    public String getEntval() {
        return entval;
    }

    public void setEntval(String entval) {
        this.entval = entval;
    }

    /**
     *
     * @return ссылку на переменную mib для этих данных
     */
    public Mibent getMibent() {
        return mibent;
    }

    public void setMibent(Mibent mibent) {
        this.mibent = mibent;
    }

    @XmlTransient
    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Eventdata)) {
            return false;
        }
        Eventdata other = (Eventdata) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.crimsec.utils.snmp.model.Eventdata[ id=" + id + " ]";
    }
}
